package com.fuqi.android.zhongcai.utils;

import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.Signature;

import com.fuqi.android.zhongcai.application.UniApplication;

/**
 * Created by admin on 2015/7/31.
 */
public class VersionUtils {

    public static String getPackageName() {
        return getPackageInfo().packageName;

    }


    public static int getVersionCode() {
        return getPackageInfo().versionCode;

    }


    public static String getVersionName() {

        return getPackageInfo().versionName;
    }

    public static String getSignature() {
        StringBuilder builder;
        String signatureStr;
        Signature[] signatures = getPackageInfo().signatures;
        builder = new StringBuilder();
        for (Signature signature : signatures) {
            builder.append(signature.toCharsString());
        }
        signatureStr = builder.toString();

        return signatureStr;
    }


    public static PackageInfo getPackageInfo() {
        PackageManager manager;

        PackageInfo info = null;

        manager = UniApplication.getInstance().getPackageManager();

        try {

            info = manager.getPackageInfo(UniApplication.getInstance().getPackageName(), 0);

        } catch (PackageManager.NameNotFoundException e) {

// TODO Auto-generated catch block

            e.printStackTrace();

        }


        return info;
    }


}
